<?xml version="1.0" encoding="utf-8" ?>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<jsp:include page="/commonPart/htmlHeader2.jsp">
	<jsp:param name="title" value="站内留言-${userInfo.name}的个人空间-CommonWorld" />
</jsp:include>
<body>
<div id = "CW_Screen" >
	<jsp:include page= "/commonPart/bodyHeader2.jsp" ></jsp:include>
	<div id = "CW_Content">
		<div id = "SpaceLeft">
			<div class = "AdminNav clearfix">
				<a href = "${userUrls.home}" class = "u" title = "返回我的空间首页">
					<img src = "${initParam.webContentPath}${userInfo.headImage}" alt = "${userInfo.name}" class = "SmallPortrait" user = "${userInfo.id}" />	
				</a>
				<span class = "h">空间管理</span>
			</div>
			<div id = "AdminMenus" class = "Mod">
				<ul>
					<li class = "caption">
						<strong>个人信息管理</strong>
						<ol>
							<li class = "active"><a href = "${userUrls.adminInbox}">站内留言</a></li>
							<li><a href = "${userUrls.adminProfile}">修改个人资料</a></li>
							<li><a href = "${userUrls.adminChqwd}">更改登录密码</a></li>
							<li><a href = "${userUrls.adminPortrait}">更改头像图片</a></li>
						</ol>
					</li>
				</ul>
				<ul>
					<li class = "caption">
						<strong>博客管理</strong>
						<ol>
							<li><a href = "${userUrls.adminNewBlog}">发表博客</a></li>
							<li><a href = "${userUrls.adminDrafts}">草稿箱(${draftInfos.count})</a></li>
							<li><a href = "${userUrls.adminBlogCatalogs}">博客设置/分类管理</a></li>
						</ol>
					</li>
				</ul>
			</div>		
		</div>
		<div class = "SpaceList" id = "AdminBody">
			<div class = "TopBar">
				<div class = "NavPath">
				</div>
			</div>
			<div class = "AdminHead">
				<h1>
					<a href = "${userUrls.adminInbox}">留言</a> &raquo; ${otherName}
					<span class = "SubTitle">共有${totalMsgs}条留言</span>
				</h1>
			</div>
			<div class = "AdminContent">
				<div class = "MsgForm">
					<strong>发送留言给 ${otherName}</strong>
					<form id = "FormMsg">
						<input name = "where" type = "hidden" value = "msgs" />
						<input name = "receiverId" type = "hidden" value = "${otherId}" />
						<textarea name = "content" class = "TEXT" id = "msg_content"></textarea>
						<br />
						<div style = "overflow: hidden;">
							<a class = "rndbutton" href = "javascript:sendMsgToUser(${otherId})"><span>发送留言</span></a>
						</div>
					</form>
				</div>
				<ul class = "Msgs" id = "UserMsgs">
					<c:forEach items="${msgs}" var="msg">
						<li class = "${msg.senderId == userInfo.id ? 'wo' : 'ta'}" id = "Msg_${msg.msgId}">
							<table class = "ostable">
								<tr>
									<td class = "user">
										<a href = "${initParam.webRootUrl}u/${msg.senderId}" target="_blank">
											<img title = "${msg.senderName}" align = "absmiddle" class = "SmallPortrait" alt = "${msg.senderName}" src = "${msg.senderHeadImage}" user = "${msg.senderId}"></img>
										</a>
									</td>
									<td>
										<div class = "msg">
											${msg.content}
										</div>
										<div class = "bottom">
											<span class = "date">
												${msg.sendTime}
											</span>
											<span class = "opts">
												<a title = "删除此条留言" href = "javascript:delete_msg(${msg.msgId})">删除</a>
											</span>
										</div>
									</td>
								</tr>
							</table>
						</li>
					</c:forEach>
				</ul>
				<ul class = "pager">
					<c:if test="${currentPage > 1}">
						<li class = "page prev">
							<a href = "?user=${param.user}&p=${currentPage - 1}">&lt;</a>
						</li>
					</c:if>
					<c:if test = "${beginIndex > 1 }">
						<li class = "page">
							<a href = "?user=${param.user}&p=1">1</a>
						</li>
					</c:if>
					<c:forEach items="${pages}" var = "page">
						<li class = "page ${currentPage == page ? 'current' : ''}">
							<a href = "?user=${param.user}&p=${page}">${page}</a>
						</li>
					</c:forEach>
					<c:if test = "${endIndex < totalPage}">
						<li class = "page">
							<a href = "?user=${param.user}&p=${totalPage}">${totalPage}</a>
						</li>
					</c:if>
					<c:if test = "${currentPage < totalPage}">
						<li class = "page next">
							<a href = "?user=${param.user}&p=${currentPage + 1}">&gt;</a>
						</li>
					</c:if>
				</ul>
			</div>
			<div id = "msg_temp" style = "display:none;">
				<li class = "wo" id = "Msg_">
					<table class = "ostable">
						<tr>
							<td class = "user">
								<a href = "#" target="_blank">
									<img title = "#" align = "absmiddle" class = "SmallPortrait" alt = "#" src = "#" user = "#"></img>
								</a>
							</td>
							<td>
								<div class = "msg">
									content
								</div>
								<div class = "bottom">
									<span class = "date">
										sendTime
									</span>
									<span class = "opts">
										<a title = "删除此条留言" href = "javascript:delete_msg(0)">删除</a>
									</span>
								</div>
							</td>
						</tr>
					</table>
				</li>
			</div>
			<script>
				function sendMsgToUser(otherId) {
					if ($('#msg_content').val().length == 0) {
						alert('请输入留言内容');
						return;
					}
					var formData = $('#FormMsg').serialize();
					ajax_post("/action/msg/inboxSend", formData, function(result) {
						if (result.errorMsg) {
							alert(result.errorMsg);
						} else {
							$('#msg_content').val('');
							$('ul#UserMsgs').prepend($('#msg_temp').html());
							var newMsg = $('ul#UserMsgs').children('li').first();
							newMsg.attr('id', 'Msg_' + result.msgId);
							newMsg.find('.user a').attr('href', '${initParam.webRootUrl}u/' + result.senderId);
							newMsg.find('.user a img').attr({title: result.senderName, alt: result.senderName, src: result.senderHeadImage, user: result.senderId});
							newMsg.find('.msg').html(result.content);
							newMsg.find('.date').html(result.sendTime);
							newMsg.find('.opts a').attr('href', 'javascript:delete_msg('+ result.msgId +')');
						}
					});
				}
				
				function delete_msg(msgId) {
					if (confirm('你确定要删除此条留言吗？')) {
						ajax_post("/action/msg/deleteMsg", "msgId=" + msgId, function(html) {
							if (html.length > 0)
								alert(html);
							else {
								$('ul#UserMsgs').find('#Msg_' + msgId).fadeOut();
							}
						});
					}
				}
			</script>
		</div>
	</div>
	<div class = "clear"></div>
	<div id = "footer"></div>
</div>
</body>
</html>